<?php

/*

  Action - Attack	$3

  Reveal a card from your hand.
  Return up to 2 copies of it from your hand to the Supply.
  Then each other player gains a copy of it.

 */

class Ambassador extends Card implements iAction, iKingdom, iAttack, iSeaside {

    public function __construct() {
        parent::__construct("Ambassador", 3);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "Reveal a card from your hand.  Return up to 2 copies of it from your hand to the Supply.  Then each other player gains a copy of it.");
    }

    public function play(Game $game, $isRealCard) {
        $game->attack($this);
        $tmpPlayHand = $game->getPlayHand();
        $playHand = array();
        foreach ($tmpPlayHand as $tmpCard) {
            if (!$tmpCard instanceof iShelter)
                $playHand[] = $tmpCard;
        }
            
        if (sizeof($playHand) > 0) {
            $playHand = getUniqueCards($playHand);
            if (sizeof($playHand) > 1) {
                $output = MySocket::GetUserReply($game, Input_ChooseOne, $playHand, 1, 1, null, "Choose a card");
                $card = n2c($output[0]);
            } else {
                $card = $playHand[0];
            }
            $playHand = $game->getPlayHand();
            $copies = 0;
            foreach ($playHand as $phc) {
                if ($phc->getKey() == $card->getKey()) {
                    $copies++;
                }
            }
            $options = array();
            $options[] = new Option(1, "0");
            $options[] = new Option(2, "1");
            if ($copies >= 2)
                $options[] = new Option(3, "2");

            $output = MySocket::GetUserReply($game, Input_ChooseOne, $options, 1, 1, null, "How many " . $card->getValue() . "s return to kingdom pile?");

            $copies = (int) ($output[0]);
            ScreenDisplay::addScreenMessage($game, true, "return $copies copies of " . nicePrint($card) . " back to the board", "returns $copies copies of " . ScreenDisplay::$LMSG . " back to the board");
            for ($i = 0; $i < $copies; $i++) {
                $game->moveCardFromPileToPile($card, PlayHand, BoardCards);
            }


            $names = $game->getOtherPlayersNames(true);
            foreach ($names as $name) {
                $card = $game->moveCardFromPileToPile($card, BoardCards, DiscardPile, $name);
                ScreenDisplay::addScreenMessage($game, true, "gain " . nicePrint($card), "gains " . ScreenDisplay::$LMSG, $name);
            }
        }
        $game->cardActionFinished();
        return true;
    }

}

?>